package com.niiwoo.civet.trade.dto.request;

import com.alibaba.fastjson.JSON;
import com.niiwoo.civet.trade.enums.ProjectTypeEnum;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;

/**
 * 信审天秤回调dubbo服务请求参数
 * @author zhoulinquan
 * @date 2018/4/20
 */
@Setter
@Getter
public class CreditAuditBackRequestDTO implements Serializable {
	private static final long serialVersionUID = -8618032058673716243L;

	private static final int REQUEST_SUCCESS = 0;

    /**
     * 请求处理结果
     */
    private Integer status;

    /**
     * 审核结果
     */
    private Integer decision;

    /**
     * 标的ID
     */
    private Long projectId;
    
    /**
     * 流程ID
     */
    private Long flowId;
    
    /**
     * 项目类型
     */
    private Byte projectType;

    /**
     * 审核结果
     */
    private Byte auditResult;

    /**
     * 审核要点
     */
    private String auditPoints;

    /**
     * 信审要点反欺诈结果枚举
     */
    @Getter
    @AllArgsConstructor
    public enum AuditResultEnum {
        PASS(0, "通过"),
        REJECT(1, "拒绝"),
        NEED_REVIEW(2, "需要人工审核");

        private final Integer code;
        private final String desc;

        public Integer getCode() {
            return code;
        }

        public String getDesc() {
            return desc;
        }
        
        public static AuditResultEnum enumof(int code) {
        	switch (code) {
        	case 0:
        		return PASS;
        	case 1:
        		return REJECT;
        	case 2:
        		return NEED_REVIEW;
        	}
        	
        	return null;
        }
    }

    @Override
    public String toString() {
        return JSON.toJSONString(this);
    }

    /**
     * 请求成功?
     * @return
     */
    public boolean isRequestSuccess(){
        return status == REQUEST_SUCCESS;
    }

    /**
     * 审核通过?
     * @return
     */
    public boolean isAuditPass(){
        return decision == AuditResultEnum.PASS.getCode();
    }

    /**
     * 审核拒绝?
     * @return
     */
    public boolean isAuditReject(){
        return decision == AuditResultEnum.REJECT.getCode();
    }

    /**
     * 需要人工审核?
     * @return
     */
    public boolean isAuditReview(){
        return decision == AuditResultEnum.NEED_REVIEW.getCode();
    }
    
    /**
     * 获取简要审核结果
     * @return
     */
    public String buildAuditPoints(){
    	AuditResultEnum auditResult = AuditResultEnum.enumof(decision);
    	
    	return auditResult.getDesc();
    }
    
    /**
     * 项目类型
     * @return
     */
    public ProjectTypeEnum getProjectType(){
        return ProjectTypeEnum.getEnum(projectType);
    }
}
